home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6742 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  45 lines

  1. Path: sun001.spd.dsccc.com!spd!jmccarty
  2. From: jmccarty@spd.dsccc.com (Mike McCarty)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Easiest way to center a string?
  5. Date: 14 Feb 1996 19:54:33 GMT
  6. Organization: DSC Communications Corporation, Plano, Texas USA
  7. Message-ID: <4ftelp$b7l@sun001.spd.dsccc.com>
  8. References: <4fobka$1st@parlor.hiwaay.net> <3120d412.7714326@news.iquest.net>
  9. NNTP-Posting-Host: aplo139.spd.dsccc.com
  10.  
  11. In article <3120d412.7714326@news.iquest.net>,
  12. Robert B. Clark <rclark@iquest.net> wrote:
  13. )On 12 Feb 1996 21:31:54 GMT, foxworth@hiwaay.net wrote:
  14. )
  15. )>  I'm learning C, and one of my assignments requires that the output strings be
  16. )>centered on the screen. Is there a simple way of doing this that I have overlooked?
  17. )
  18. )Compute the left column by subtracting half of the string length from
  19. )half of the screen width; e.g.,
  20. )
  21. )    x=MAXCOL / 2 - strlen(str) / 2;
  22. )
  23. )where MAXCOL is the maximum number of columns available to you (text
  24. )mode DOS, 80 columns).  'x' will be the column in which you should start
  25. )printing your string.
  26. )
  27. )You didn't mention which platform you're compiling for, so I leave the
  28. )details of cursor positioning to you.  If you're on a DOS machine, look
  29. )up gotoxy().
  30. )--
  31. )Robert B. Clark <rclark@iquest.net>
  32. )"Be wary of strong spirits.  It can make you shoot at tax collectors...
  33. )and miss." --RAH
  34.  
  35.  
  36. Please do =not= use this code as it stands. It may do terrible things to
  37. your screen if the string does not fit into the field. Always check for
  38. fits before using such techniques.
  39.  
  40. Mike
  41. ----
  42. char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
  43.  
  44. I don't speak for DSC.         <- They make me say that.
  45.